home *** CD-ROM | disk | FTP | other *** search
/ Power CD / Power CD ATARI-Rechner Lieben.iso / DEMOS / HM2_DEMO / BSP / MILLERFW.M < prev    next >
Encoding:
Text File  |  1993-03-20  |  5.7 KB  |  262 lines

  1. MODULE Miller_f_Win;
  2. (* Dieses Modul kann nur mit aktivierter Option f (Coprozessor) compiliert
  3.      werden (sonst existiert das Pseudo-Modul FPU nicht). Ohne direkte Verwendung
  4.      der FLine-FPU wäre das Programm zu langsam. *)
  5.  
  6. FROM FPU IMPORT SIN, COS, EXTEND, WHOLE;
  7. IMPORT AES, appl, evnt, graf, MathLib0, VDI, v, vr, vs, vsf, vsl, wind;
  8. FROM SYSTEM IMPORT ADR;
  9.  
  10. CONST
  11.     cStep = 0.03;
  12.     N = VAL (LONGINT, TRUNC (200.0 * MathLib0.pi / cStep + 0.5));
  13.  
  14. VAR
  15.     hdl: SHORTINT;
  16.  
  17. PROCEDURE init(): BOOLEAN;
  18.  
  19.     TYPE
  20.         tIn = ARRAY [0..10] OF SHORTINT;
  21.  
  22.     VAR
  23.         in: tIn;
  24.         out: ARRAY [0..56] OF SHORTINT;
  25.         j: SHORTINT;
  26.  
  27.     BEGIN
  28.         IF appl.init () < 0 THEN RETURN FALSE END;
  29.         (*VDI init*)
  30.         in := tIn{1 BY 10, 2};
  31.         hdl := graf.handle (j, j, j, j);
  32.         v.opnvwk (in, hdl, out);
  33.         IF hdl > 0 THEN
  34.             RETURN TRUE
  35.         ELSE
  36.             appl.exit;
  37.             RETURN FALSE
  38.         END;
  39.     END init;
  40.  
  41. VAR
  42.     wname: ARRAY [0..49] OF CHAR;
  43.  
  44. PROCEDURE intersect (VAR w1, w2: AES.tRect): BOOLEAN;
  45.  
  46.     VAR
  47.         (*$Reg*) xmin, (*$Reg*) ymin,
  48.         (*$Reg*) xmax, (*$Reg*) ymax,
  49.         (*$Reg*) x2, (*$Reg*) y2: SHORTINT;
  50.  
  51.     BEGIN
  52.         WITH w1 DO
  53.             x2 := x+w;
  54.             y2 := y+h;
  55.             xmin := x;
  56.             ymin := y;
  57.         END;
  58.         WITH w2 DO
  59.             IF x > xmin THEN xmin := x END;
  60.             IF y > ymin THEN ymin := y END;
  61.             xmax := x+w; IF x2 < xmax THEN xmax := x2 END;
  62.             ymax := y+h; IF y2 < ymax THEN ymax := y2 END;
  63.             w2 := AES.tRect{xmin, ymin, xmax-xmin, ymax-ymin};
  64.             RETURN ~((w <= 0) OR (h <= 0));
  65.         END
  66.     END intersect;
  67.  
  68. PROCEDURE Main;
  69.  
  70.     CONST
  71.         cPoints = 100;
  72.  
  73.     TYPE
  74.         tVRect = ARRAY [0..1] OF VDI.tPoint;
  75.  
  76.     VAR
  77.         w2, h2: LONGINT;
  78.         (*$Reg*) ox, (*$Reg*) oy: LONGINT;
  79.         (*$Reg*) a,
  80.         (*$Reg*) b,
  81.         (*$Reg*) t: LONGREAL;
  82.         (*$R+*) i: LONGINT;
  83.         (*$Reg*) j: SHORTINT;
  84.         Points: ARRAY [0..cPoints-1] OF VDI.tPoint;
  85.         color: SHORTINT;
  86.         wrect, desk: AES.tRect;
  87.         fulled: BOOLEAN;
  88.         FParam: wind.tFParam;
  89.         w: SHORTINT;
  90.         stop, resize, reset: BOOLEAN;
  91.     
  92.     PROCEDURE redraw (wrect: AES.tRect);
  93.  
  94.         VAR
  95.             vrect: tVRect;
  96.             rect: AES.tRect;
  97.  
  98.         BEGIN
  99.             wind.update (wind.BegUpdate);
  100.             IF intersect (desk, wrect) THEN
  101.                 v.hidec (hdl);
  102.                 wind.get (w, wind.FirstXYWH, rect);
  103.                 WHILE (rect.w > 0) & (rect.h > 0) DO
  104.                     IF intersect (wrect, rect) THEN
  105.                         WITH rect DO vrect := tVRect{{x,y},{x+w-1,y+h-1}} END;
  106.                         vs.clip (hdl, TRUE, vrect);
  107.                         vr.recfl (hdl, vrect);
  108.                     END;
  109.                     wind.get (w, wind.NextXYWH, rect);
  110.                 END;
  111.                 v.showc (hdl, FALSE);
  112.             END;
  113.             wind.update (wind.EndUpdate);
  114.         END redraw;
  115.  
  116.     PROCEDURE draw (n: SHORTINT);
  117.  
  118.         CONST
  119.             cMinW = 160;
  120.             cMinH = 160;
  121.  
  122.         VAR
  123.             msg: evnt.tMsg;
  124.             event: BITSET;
  125.             vrect: tVRect;
  126.             rect: AES.tRect;
  127.  
  128.         BEGIN
  129.             wind.update (wind.BegUpdate);
  130.             v.hidec (hdl);
  131.             wind.get (w, wind.FirstXYWH, rect);
  132.             WHILE (rect.w > 0) & (rect.h > 0) DO
  133.                 IF intersect (desk, rect) THEN
  134.                     WITH rect DO vrect := tVRect{{x,y},{x+w-1,y+h-1}} END;
  135.                     vs.clip (hdl, TRUE, vrect);
  136.                     v.pline (hdl, n, Points);
  137.                 END;
  138.                 wind.get (w, wind.NextXYWH, rect);
  139.             END;
  140.             v.showc (hdl, FALSE);
  141.             wind.update (wind.EndUpdate);
  142.             AES.intin[14] := 20;
  143.             AES.intin[15] := 0;
  144.             AES.addrin[0] := ADR (msg);
  145.             event := evnt.pmulti ({evnt.Mesag, evnt.Timer});
  146.             IF evnt.Mesag IN event THEN
  147.                 IF msg.win = w THEN
  148.                     CASE msg.type OF
  149.                     | evnt.Closed:
  150.                             stop := TRUE;
  151.                     | evnt.Topped:
  152.                             FParam.handle := w;
  153.                             wind.set (w, wind.Top, FParam.rect);
  154.                     | evnt.Fulled:
  155.                             IF fulled THEN
  156.                                 wind.get (w, wind.PrevXYWH, FParam.rect);
  157.                                 fulled := FALSE;
  158.                             ELSE
  159.                                 wind.get (w, wind.FullXYWH, FParam.rect);
  160.                                 fulled := TRUE;
  161.                             END;
  162.                             wind.set (w, wind.CurrXYWH, FParam.rect);
  163.                             resize := TRUE; reset := TRUE;
  164.                     | evnt.Moved, evnt.Sized:
  165.                             FParam.coord := msg.coord;
  166.                             WITH FParam.coord DO
  167.                                 IF w < cMinW THEN w := cMinW END;
  168.                                 IF h < cMinH THEN h := cMinH END;
  169.                             END;
  170.                             wind.set (w, wind.CurrXYWH, FParam.rect);
  171.                             resize := TRUE;
  172.                             reset := msg.type = evnt.Sized;
  173.                     | evnt.Redraw:
  174.                             redraw (msg.coord);
  175.                             VOID (vsl.color (hdl, VDI.Black));
  176.                             color := VDI.Black;
  177.                     END
  178.                 END
  179.             END;
  180.         END draw;
  181.  
  182.     BEGIN
  183.         IF init() THEN
  184.             graf.mouseform (graf.Arrow);
  185.             wind.get (0, wind.WorkXYWH, desk);
  186.             w := wind.create (
  187.                  {wind.cName, wind.cClose, wind.cFull, wind.cMove, wind.cSize},
  188.                  desk);
  189.             wname := ' Miller - mit Hänisch Modula-2 programmiert ';
  190.             FParam.string := ADR (wname);
  191.             wind.set (w, wind.Name, FParam.rect);
  192.             wrect := desk;
  193.             WITH wrect DO
  194.                 w := w DIV 2;
  195.                 h := h DIV 2;
  196.             END;
  197.             fulled := FALSE;
  198.             wind.open (w, wrect);
  199.             VOID (vsf.color (hdl, VDI.White));
  200.             color := VDI.Black;
  201.             stop := FALSE; resize := TRUE; reset := FALSE;
  202.             LOOP
  203.                 t := 0.0;
  204.                 VOID (vsl.color (hdl, color));
  205.                 j := 0;
  206.                 i := 0;
  207.                 WHILE i <= N DO
  208.                     INC (i);
  209.                     IF stop THEN EXIT END;
  210.                     IF resize THEN
  211.                         wind.get (w, wind.WorkXYWH, wrect);
  212.                         WITH wrect DO
  213.                             w2 := w DIV 2;
  214.                             h2 := h DIV 2;
  215.                             a := EXTEND (w2) / 2.0;
  216.                             b := EXTEND (h2) / 1.3;
  217.                             ox := x + w2;
  218.                             oy := y + h2;
  219.                         END;
  220.                         resize := FALSE;
  221.                         j := 0;
  222.                     END;
  223.                     IF reset THEN
  224.                         wind.get (w, wind.WorkXYWH, wrect);
  225.                         redraw (wrect);
  226.                         VOID (vsl.color (hdl, VDI.Black));
  227.                         color := VDI.Black;
  228.                         j := 0; i := 0; t := 0.0;
  229.                         reset := FALSE;
  230.                     END;
  231.                     INC (t, cStep);
  232.                     Points[j] := VDI.tPoint{
  233.                             ox + WHOLE (a * (SIN (0.99 * t) - 0.7 * COS (3.01 * t))),
  234.                             oy + WHOLE (b * (COS (1.01 * t) + 0.1 * SIN (15.03 * t)))
  235.                     };
  236.                     INC (j);
  237.                     IF j = cPoints THEN
  238.                         draw (cPoints);
  239.                         Points[0] := Points[cPoints-1];
  240.                         j := 1
  241.                     END
  242.                 END;
  243.                 IF j > 1 THEN
  244.                     draw (j)
  245.                 END;
  246.                 IF color = VDI.Black THEN
  247.                     color := VDI.White
  248.                 ELSE
  249.                     color := VDI.Black
  250.                 END;
  251.             END;
  252.             wind.close (w);
  253.             wind.delete (w);
  254.             v.clsvwk (hdl);
  255.             appl.exit ()
  256.         END;
  257.     END Main;
  258.  
  259. BEGIN
  260.     Main
  261. END Miller_f_Win.
  262.         
  263.     
  264.